package 剑指offer;

import java.util.Arrays;

public class 矩阵转换 {
    public static int[][] transponseSMatrix(int[][] matrix) {
        int[][] newMatrix = new int[matrix[0].length][matrix.length];
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[0].length; j++) {
                newMatrix[j][i] = matrix[i][j];
            }
        }
        return newMatrix;
    }

    public static void main(String[] args) {
        int[][] matrix = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
        int[][] transponseSMatrix = transponseSMatrix(matrix);
        for (int i = 0; i < transponseSMatrix.length; i++) {

            System.out.println(Arrays.toString(transponseSMatrix[i]));
        }

    }
}
